import 'package:flutter/material.dart';
import 'package:flutter_1911/model/common_model.dart';
import 'package:flutter_1911/until/nav_until.dart';
import 'package:flutter_1911/widget/webview.dart';

class Local extends StatelessWidget {
  final List<CommonModel> localList;
  const Local({Key? key, required this.localList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 64,
      decoration: const BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(//设置背景圆角
            Radius.circular(6),
        ),
      ),
      child: Padding(
        padding: const EdgeInsets.all(7),
        child: _items(context),
      ),
    );
  }
  _items(BuildContext context){
    List<Widget> item = [];
    localList.forEach((element) {
      //遍历集合
      item.add(_item(context,element));
    });
    print(localList);
    //横排排列
    return Row(
      //平均排列
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: item,
    );
  }
  //上下结构
  Widget _item(BuildContext context,CommonModel element){
    return GestureDetector(
      onTap: (){
        //点击事件 跳转相应的webview
        NavigatorUtil.push(
            context,
          HiWebView(
            //获取当前webview的地址
            url: element.url,
            //获取webview的状态栏的颜色
            statusBarColor: element.statusBarColor,
            //隐藏appbar
            hideAppBar: element.hideAppBar,
          )
        );
      },
      child: Column(
        children: [
          Image.network(
            //获取导航栏的图标
            element.icon!,
            //设置宽高
            width: 32,
            height: 32,
          ),
          Text(
            //获取导航栏的标题
            element.title!,
            //设置字体大小
            style: TextStyle(fontSize: 12),
          )
        ],
      ),
    );
  }
}
